package com.wu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wu.mapper.CommentsMapper;
import com.wu.mapper.UserLevelMapper;
import com.wu.pojo.UserLevel;
import com.wu.service.UserLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author: 吴磊
 * @program: blog
 * @create: 2021-05-06 22:11
 */
@Service
public class UserLevelServiceImpl extends ServiceImpl<UserLevelMapper, UserLevel> implements UserLevelService {

    @Autowired
    private UserLevelMapper userLevelMapper;


    @Autowired
    private CommentsMapper commentsMapper;


    @Override
    public Map<String, String> getUserLevelByArticleId(String articleId) {
        Set<String> userIds = commentsMapper.getUserIdsByArticleId(articleId);
        ArrayList<String> strings = new ArrayList<>(userIds);
        Map<String, String> map = new HashMap();
        if (strings.size() <= 0 || strings == null) {
            return map;
        }
        List<UserLevel> UserLevels = userLevelMapper.getLevelBeanByUserId(strings);
        for (UserLevel userLevel : UserLevels) {
            map.put(userLevel.getUserId(), userLevel.getUserLevel());
        }
        return map;
    }
}
